package com.xm.apd.nettyclient;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.xm.apd.nettyclient.netty.Client;
import com.xm.apd.nettyclient.netty.ClientMsgHandler;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.btn_send)
    Button send;
    @BindView(R.id.tv)
    TextView tv;
    @BindView(R.id.et)
    EditText editText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_send,R.id.btn_connect})
    public void OnClick(View v){
        switch (v.getId()){
            case R.id.btn_send:
                String s = editText.getText().toString();
                if (TextUtils.isEmpty(s))
                    return;
                ClientMsgHandler.send(s);
                break;
            case R.id.btn_connect:
                final String ip = editText.getText().toString();
                if (TextUtils.isEmpty(ip))
                    return;
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        Client.connect(ip);
                    }
                }).start();

                break;
        }
    }
}
